package com.meiyou.service.impl;

import com.meiyou.mapper.ArticleMapper;
import com.meiyou.mapper.UserMapper;
import com.meiyou.service.SystemService;
import com.meiyou.vo.SystemByMonthVo;
import com.meiyou.vo.UserAndArticleByMonthVo;
import com.meiyou.vo.UserAndArticleVo;
import com.meiyou.vo.UserByAddressVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SystemServiceImp implements SystemService {

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private ArticleMapper articleMapper;

    /**
     * 获取总用户数和总文章数
     *
     * @return
     */
    @Override
    public UserAndArticleVo getUserAndArticleNum() {

        Integer userNum = userMapper.count();

        Integer articleNum = articleMapper.count();

        return UserAndArticleVo.builder()
                .articleNum(articleNum)
                .userNum(userNum).build();
    }

    /**
     * 获取最近三个月用户数和文章数
     *
     * @return
     */
    @Override
    public UserAndArticleByMonthVo getUserAndArticleNumByMonth() {

        List<SystemByMonthVo> userList = userMapper.selectByMonth();

        List<SystemByMonthVo> articleList = articleMapper.selectByMonth();

        return UserAndArticleByMonthVo.builder()
                .articleList(articleList)
                .userList(userList).build();
    }

    /**
     * 获取每个地区的用户占比，前五
     *
     * @return
     */
    @Override
    public List<UserByAddressVo> getUserByAddress() {

        List<UserByAddressVo> userList = userMapper.getByAddress();

        return userList;
    }
}
